<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <link href="../css/swiper.min.css" rel="stylesheet"/>
    <style>
    .x-ico-month .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.x-ico-month .el-input__prefix{
      display: none;
    }.el-dialog .el-input__inner{
      border: 1px solid #ccc;
    }.x-matefill .el-form-item__content{
      margin-left: 50px;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">填报日盘（主料）</div>
      </div>
      <div class="container">
        <!--  -->
        <div class="x-ico-month">
          <el-date-picker v-model="cardsmonth" type="date" placeholder="选择日" @change="getmonth" format="yyyy 年 MM 月dd 日" value-format="yyyyMMdd" :editable="notkey"></el-date-picker>
        </div>
        <!--  -->
  			<div class="x-train-tabs swiper-container">
  				<div class="swiper-wrapper">
  					<div class="swiper-slide x-train-items" v-for="(item,index) in tabsdata" :key="item.id" @click="changetab(index,item.id)" :class="{active:curId==index}">{{item.title}}</div>
  				</div>
  			</div>
        <div class="">
          <template>
            <el-table :data="tabledata" @cell-click="gotrainpro" :cell-class-name="tableCellClassName">
              <el-table-column label="品名" width="90" fixed>
                <template slot-scope="scope">
                  {{scope.row.title}}
                </template>
              </el-table-column>
              <el-table-column label="存规格" width="">
                <template slot-scope="scope">
                  {{scope.row.save_unit}}
                </template>
              </el-table-column>
              <el-table-column label="毛料" width="">
                <template slot-scope="scope">
                  <div v-if="scope.row.gross!=''">{{scope.row.gross}}</div>
                  <div v-else>0</div>
                </template>
              </el-table-column>
              <el-table-column label="净料" width="">
                <template slot-scope="scope">
                  <div v-if="scope.row.gross!=''">{{scope.row.net}}</div>
                  <div v-else>0</div>
                </template>
              </el-table-column>
              <el-table-column label="调拨" width="">
                <template slot-scope="scope">
                  <div v-if="scope.row.gross!=''">{{scope.row.allot}}</div>
                  <div v-else>0</div>
                </template>
              </el-table-column>
              <el-table-column label="报损" width="">
                <template slot-scope="scope">
                  <div v-if="scope.row.gross!=''">{{scope.row.loss}}</div>
                  <div v-else>0</div>
                </template>
              </el-table-column>
              <el-table-column label="操作" width="" >
                <template slot-scope="scope">
                  <el-button type="text" v-if="noget==0">编辑</el-button>
                  <div v-else>无</div>
                </template>
              </el-table-column>
            </el-table>
          </template>
          <div class="x-table-desc">盘点人：{{askname}}</div>
        </div>
        <!--  -->
        <div class="x-pro-gobtn" @click="isok" v-if="noget==0">提交</div>
        <div class="x-pro-gobtn x-disabled" v-if="noget==1">已提交</div>
		  </div>
      <!-- <div class="x-nothing" v-show="noshow">暂无权限</div> -->
      <!--  -->
      <el-dialog title="" :visible.sync="dialogFormVisible" width="80%">
        <el-form :model="form" class="x-matefill">
          <el-form-item label="品名:">
            {{form.title}}
          </el-form-item>
          <el-form-item label="毛料:">
            <el-input v-model="form.num1" type="number"></el-input>
          </el-form-item>
          <el-form-item label="净料:">
            <el-input v-model="form.num2" type="number"></el-input>
          </el-form-item>
          <el-form-item label="调拨:">
            <el-input v-model="form.num3" type="number"></el-input>
          </el-form-item>
          <el-form-item label="报损:">
            <el-input v-model="form.num4" type="number"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="formget">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="../script/swiper.min.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          tabsdata:'',
          curId:0,
          tabledata:[],
          cardsmonth:'',
          cardsmonthtoy:'',
          cardsmonthtom:'',
          tabsid:0,
          notkey:false,
          isfromindex:true,
          noget:-1,
          askname:'',
          yesshow:false,
          noshow:false,
          dialogFormVisible:false,
          form:{
            title:'',
            num1:'',
            num2:'',
            num3:'',
            num4:''
          },
          rownum:-1,
          isclick:true,
        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        var day = date.getDate();
        if(month<10){
          month = '' + 0 + month;
        }
        if(day<10){
          day = '' + 0 + day;
        }
        var toMonth = '' + year + month + day;
        that.cardsmonth = toMonth;
        that.cardsmonthtoy = year;
        that.cardsmonthtom = month;
        that.getswiper()
      },
      methods: {
        //校验不为空
        isokget:function(){
          var that = this;
          // for(var i=0;i<that.tabledata.length;i++){
          //   if(that.tabledata[i].buy_num==''){
          //     api.toast({
          //         msg: '请填写叫货量',
          //         duration: 3000,
          //         location: 'bottom'
          //     });
          //     return;
          //   }else{
          //     console.log('提交');
          //     // that.isok()
          //   }
          // };
          let flag = that.tabledata.every(item => !!item.buy_num)
          if (!flag) {
            api.toast({
                msg: '请填写叫货量',
                duration: 3000,
                location: 'bottom'
            });
            return;
          }else{
            that.isok()
          }
        },
        //提交
        isok:function(){
          let that=this;
          // if(that.isclick){
            that.isclick = false
            api.ajax({
              url:baseurl+'api/material/addInventoryOrder',
              methods:'get',
              data:{
                values:{
                  sec: $api.getStorage('apptoken'),
                  wsid:that.tabsid,
                  date:that.cardsmonth,
                  num_json:that.tabledata
                }
              }
            },function(ret,err){
              if(ret){
                api.hideProgress();
                console.log(JSON.stringify(ret));
                if(ret.status == 1){
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                  that.gettrainadmin()
                }else{
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                }
              }else{
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: err.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            })
          // }
          
        },
        //切换选择日期
        getmonth:function(val){
          var that = this;
          // console.log(val);
          // console.log(val.getMonth()+1);
          // var tmon = val.getMonth()+1
          // if(tmon<10){
          //   tmon=''+0+tmon
          // }
          // console.log(''+val.getFullYear() + tmon);
          that.cardsmonth = val;
          that.cardsmonthtoy = that.cardsmonth.slice(0,4);
          that.cardsmonthtom = that.cardsmonth.slice(4,6);
          that.gettrainadmin()

        },
        //
        tableCellClassName({row, column, rowIndex, columnIndex}){
          //注意这里是解构
          //利用单元格的 className 的回调方法，给行列索引赋值
          row.index=rowIndex;
          column.index=columnIndex;
        },
        //点击列
        gotrainpro:function(val){
          // console.log(JSON.stringify(val));
          // console.log(val.index);
          var that = this;
          that.rownum = val.index;//第几行
          that.dialogFormVisible = true;
          //
          that.form.title = val.title;
          that.form.num1 = val.gross;//毛料
          that.form.num2 = val.net;//净料
          that.form.num3 = val.allot;//调拨
          that.form.num4 = val.loss;//报损

          // api.openWin({
          //     name: 'intraindesc',
          //     url: './intraindesc.html',
          //     pageParam: {
          //         id: val.id,
          //         levelid:val.up_levelid
          //     }
          // });
        },
        //弹窗提交
        formget:function(){
          var that = this;
          that.tabledata[that.rownum].gross=that.form.num1;
          that.tabledata[that.rownum].net=that.form.num2;
          that.tabledata[that.rownum].allot=that.form.num3;
          that.tabledata[that.rownum].loss=that.form.num4;
          console.log(JSON.stringify(that.tabledata));
          that.dialogFormVisible = false;
          // that.isok()

        },
        //切换选项卡 表格数据
        changetab:function(index,id){
          var that = this;
          that.curId = index;
          that.tabsid = id;
          that.gettrainadmin()
      		// mySwiper.slideToLoop(index, 500, false);
        },
        //swiper
        getswiper:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/wsList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                type:'4'
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                  if(ret.data.length==0){
                    that.noshow = true;
                    that.yesshow = false;
                  }else{
                    that.yesshow = true;
                    that.noshow = false;
                    that.tabsdata = ret.data;
                    that.tabsid = ret.data[0].id;
                    that.gettrainadmin()
                  }
                  that.$nextTick(function(){
                    var mySwiper = new Swiper('.swiper-container',{
                      freeMode: true,
                      loop:false,//设置 active slide 居中后，会有左右留白现象，添加此会让未尾的导航补齐前后空白
                      slideToClickedSlide: true,//设置为true则点击slide会过渡到这个slide。
                      slidesPerView: 3.5,
                      centeredSlides: false,//设定为true时，active slide会居中，而不是默认状态下的居左。
                      spaceBetween: 10,//slide之间设置距离
                      slidesOffsetBefore: 0,//设定slide与左边框的预设偏移量
                      slidesOffsetAfter: 0,//设定slide与右边框的预设偏移量

                    });

                  });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //表格data
        gettrainadmin:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/inventoryList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                wsid:that.tabsid,
                date:that.cardsmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                  if(ret.data.list.length == 0){
                    that.tabledata = [];
                    that.noget = 3;
                  }else{
                    that.tabledata = ret.data.list;
                    that.noget = ret.data.is_order;
                    that.askname = ret.data.set_username;
                  }


              }else if(ret.status == 0){
                that.tabledata = [];
                that.noget = 3;
                that.askname = '';
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}

	</script>
</body>
</html>
